import com.android.build.api.dsl.ApplicationExtension
import ext.conf
import ext.configureAndroidCompose
import ext.configureAndroidDep
import ext.configureFlavors
import ext.configureKotlinAndroid
import ext.configureKotlinDep
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.kotlin

class AndroidApplicationPlugin : Plugin<Project> {

    override fun apply(target: Project) {
        with(target) {
            with(pluginManager) {
                apply("com.android.application")
                apply("org.jetbrains.kotlin.android")
                apply("com.google.devtools.ksp")
                apply("org.jetbrains.kotlin.plugin.parcelize")
                apply("org.jetbrains.kotlin.plugin.serialization")
            }

            extensions.configure<ApplicationExtension> {
                defaultConfig.targetSdk = conf.targetSdk
                configureKotlinAndroid(this)
                configureAndroidCompose(this)
                configureFlavors(this)
            }

            configureKotlinDep()
            configureAndroidDep()
            dependencies {
                add("androidTestImplementation", kotlin("test"))
                add("testImplementation", kotlin("test"))
            }
        }
    }

}
